// api/product.js
import request from '@/utils/request';
import qs from 'qs';

export const getProducts = (params) => {
    // ✅ 直接把 params 对象传给 axios，它会自动处理成 ?keyword=xx&page=1...
    return request.get('/api/user/products.do', { params });
};


export const getProductDetail = (productId) => {
    return request.get('/api/user/product/detail.do', { params: { productId } });
};

export const addProduct = (data) => {
    const formData = qs.stringify(data);
    return request.post('/api/admin/product/add.do', formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};

export const updateProduct = (data) => {
    const formData = qs.stringify(data);
    return request.post('/api/admin/product/update.do', formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};
export const deleteProduct = (productId) =>
    request.post('/api/admin/product/delete.do', qs.stringify({ productId }))